/**
 * Created by geo on 17/4/19.
 */
//外部迭代器
var Iterator = function(obj){
    var current = 0;
    var next = function () {
        current += 1;
    };
    var isDone = function () {
        return current >= obj.length;
    };
    var getCurrentItem = function () {
        return obj[current];
    };

    return {
        next: next,
        isDone: isDone,
        getCurrentItem: getCurrentItem
    };
};

///////////////test/////////////////
var iterator = Iterator([1,2,3]);
while(!iterator.isDone()){
    console.log(iterator.getCurrentItem());
    iterator.next();
}
//1
//2
//3